package com.vvlive.caibao.smartcity.ui;

import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.vvlive.caibao.smartcity.base.BaseActivity;
import com.vvlive.caibao.smartcity.bean.EnterpriseContact;
import com.vvlive.caibao.smartcity.utils.ImageUtil;
import com.vvlive.caibao.smartcity.view.CommonActionBar;

import org.kymjs.kjframe.ui.BindView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by zhj on 2015/6/29.
 */
public class CustomersContactDetailsActivity extends BaseActivity {

    @BindView(id = R.id.cc_details_name)
    private TextView mName;
    @BindView(id = R.id.cc_details_type)
    private TextView mType;

    @BindView(id = R.id.cc_details_avatar)
    private ImageView mAvatar;
    @BindView(id = R.id.cc_details_list)
    private ListView mList;

    private int[] mIcons = {
            R.mipmap.zhiweigangwei,
            R.mipmap.shouji,
            R.mipmap.dianhua,
            R.mipmap.youjian,
            R.mipmap.beizhu,
    };

    private String[] mTitles = {
            "职务", "手机", "电话", "电子邮件", "备注",
    };

    private String[] mContents = new String[5];

    @Override
    protected int getContentViewRes() {
        return R.layout.activity_ec_details;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        CommonActionBar commonActionBar = getCommonActionBar();
        commonActionBar.setTitle("客户详情");
        commonActionBar.setMoreVisible(false);

        EnterpriseContact contact = (EnterpriseContact) getIntent().getSerializableExtra("contact");
        mContents[0] = contact.getJob();
        mContents[1] = contact.getMobile();
        mContents[2] = contact.getPhone();
        mContents[3] = contact.getEmail();
        mContents[4] = contact.getMore();
        mName.setText(contact.getName());
        mType.setText(contact.getType());
        ImageUtil.loadImage(this, contact.getPortrait(), mAvatar, 0);
        SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.item_ec_details_list,
                                                         new String[]{"icon", "title", "content"}, new int[]{R.id.cc_details_icon, R.id.cc_details_title, R.id.cc_details_content});
        mList.setAdapter(adapter);
    }

    /**
     * 取得数据
     *
     * @return
     */
    private List<Map<String, Object>> getData() {
        List<Map<String, Object>> data = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("icon", mIcons[i]);
            map.put("title", mTitles[i]);
            map.put("content", mContents[i]);
            data.add(map);
        }
        return data;
    }
}
